package com.xiaoshuidi.cloud.module.rooms.controller.admin.area;

import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.module.rooms.controller.admin.area.vo.RoomAreaListReq;
import com.xiaoshuidi.cloud.module.rooms.controller.admin.area.vo.RoomAreaResp;
import com.xiaoshuidi.cloud.module.rooms.controller.admin.area.vo.RoomProvinceCityVO;
import com.xiaoshuidi.cloud.module.rooms.enums.ApiConstants;
import com.xiaoshuidi.cloud.module.rooms.service.RoomAreaService;
import com.xiaoshuidi.cloud.module.rooms.service.RoomProvinceCityService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 区域信息
 *
 * @Author Feng
 * @date 2023/5/8
 */
@Tag(name = "管理后台 - 城市区域管理")
@RequiredArgsConstructor
@RestController
@Validated
@RequestMapping(ApiConstants.NAME + "/area")
public class RoomAreaController {

    private final RoomAreaService roomAreaService;
    private final RoomProvinceCityService roomProvinceCityService;

    /**
     * 根据城市获取区域列表
     *
     * @param city
     * @return
     */
    @GetMapping("/query/district")
    @Parameter(name = "city", description = "城市")
    @Operation(summary = "根据城市获取区域列表")
    public CommonResult<List<String>> queryDistinctDistrict(@RequestParam("city") String city) {
        return CommonResult.success(roomAreaService.queryDistinctDistrict(city));
    }

    /**
     * 根据城市、区域获取板块列表
     *
     * @param city
     * @param district
     * @return
     */
    @GetMapping("/query/block")
    @Parameters({
            @Parameter(name = "city", description = "城市"),
            @Parameter(name = "district", description = "区域")
    })
    @Operation(summary = "根据城市、区域获取板块列表")
    public CommonResult<List<String>> queryDistinctBlock(String city, String district) {
        return CommonResult.success(roomAreaService.queryDistinctBlock(city, district));
    }

    /**
     * 根据城市、区域、板块、名称获取列表
     *
     * @param req
     * @return
     */
    @GetMapping("query/list")
    @Operation(summary = "根据城市、区域、板块、名称获取列表")
    public CommonResult<List<RoomAreaResp>> queryList(@Valid RoomAreaListReq req) {
        return CommonResult.success(roomAreaService.queryList(req.getCity(), req.getDistrict(), req.getStreet(), req.getName()));
    }

    @GetMapping("/getProvince")
    @Operation(summary = "获取省份")
    public CommonResult<List<RoomProvinceCityVO>> getProvince(){
        return CommonResult.success(roomProvinceCityService.getProvince());
    }

    @GetMapping("/getCity")
    @Operation(summary = "获取城市")
    public CommonResult<List<RoomProvinceCityVO>> getCity(@RequestParam("provinceName") String provinceName){
        return CommonResult.success(roomProvinceCityService.getCity(provinceName));
    }
}
